package com.xjc.business.controller.buildadmin;

import com.xjc.business.entity.po.buildadmin.*;
import com.xjc.business.entity.vo.buildadmin.BuildDetailsVo;
import com.xjc.business.entity.vo.buildadmin.CheckBedNotAddRoomVo;
import com.xjc.business.entity.vo.buildadmin.CheckBedVo;
import com.xjc.business.service.CheckBedBatchService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 徐锦程
 * 时间:2025-03-08 17:12
 */
@RestController
@RequestMapping("/build_admin/check_bed")
public class BuildCheckBedController {

    @Autowired
    CheckBedBatchService checkBedBatchService;


    /**
     * 获取当前宿舍楼宿舍列表
     * @param buildingId 宿舍id
     * @return
     */
    @GetMapping("/get_build_dormitory_list/{buildingId}")
    public Result<List<CheckBedNotAddRoomVo>> getBuildDormitoryList(@PathVariable(required = false, name = "buildingId") Integer buildingId){
        if (buildingId == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return checkBedBatchService.getBuildDormitoryList(buildingId);
    }

    /**
     * 获取当前检查宿舍信息
     * @param id 宿管id
     * @return
     */
    @GetMapping("/get_current_check_bed/{id}")
    public Result<CheckBedVo> getCurrentCheckBed(@PathVariable(required = false, name = "id") Integer id) {
        if(id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return checkBedBatchService.getCurrentCheckBed(id);
    }

    /**
     * 获取宿舍检查历史记录
     * @param id 宿管id
     * @return
     */
    @GetMapping("/get_check_bed_history_list/{id}")
    public Result<List<CheckBedVo>> getCheckBedHistoryList(@PathVariable(required = false, name = "id") Integer id){
        if(id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return checkBedBatchService.getCheckBedHistoryList(id);
    }

    /**
     * 添加检查宿舍信息
     * @param checkBedPo 检查宿舍信息
     * @return
     */
    @PostMapping("/add_check_bed")
    public Result<String> addCheckBed(@RequestBody(required = false)CheckBedPo checkBedPo){
        if (checkBedPo == null|| checkBedPo.getTypeOne() == null || checkBedPo.getTypeTwo() == null || checkBedPo.getDescInfo() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return checkBedBatchService.addCheckBed(checkBedPo);
    }

    /**
     * 删除检查宿舍信息
     * @param id 检查宿舍信息id
     * @return
     */
    @DeleteMapping("/delete_check_bed/{id}")
    public Result<String> deleteCheckBed(@PathVariable(required = false, name = "id") Integer id) {
        if (id == null) {
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return checkBedBatchService.deleteCheckBed(id);
    }

    /**
     * 添加宿舍项
     * @param checkBedRoomPo 宿舍项信息
     * @return
     */
    @PostMapping("/add_check_bed_room")
    public Result<String> addCheckBedRoom(@RequestBody(required = false) CheckBedRoomPo checkBedRoomPo){
        if (checkBedRoomPo == null || checkBedRoomPo.getBatchId()== null || checkBedRoomPo.getDormitoryId() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return checkBedBatchService.addCheckBedRoom(checkBedRoomPo);
    }

    /**
     * 删除宿舍项
     * @return
     */
    @DeleteMapping("/delete_check_bed_room/{batchId}/{roomId}")
    public Result<String> deleteCheckBedRoom(@PathVariable(required = false, name = "batchId") Integer batchId,@PathVariable(required = false, name = "roomId") Integer roomId) {
        if ( batchId == null || roomId== null) {
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return checkBedBatchService.deleteCheckBedRoom(batchId,roomId);
    }

    /**
     * 添加宿舍项学生
     * @return
     */
    @PostMapping("/add_check_bed_student")
    public Result<String> addCheckBedStudent(@RequestBody(required = false) CheckBedStudentPo checkBedStudentPo){
        if (checkBedStudentPo == null || checkBedStudentPo.getRoomId() == null || checkBedStudentPo.getBedNo() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return checkBedBatchService.addCheckBedStudent(checkBedStudentPo);
    }

    /**
     * 删除宿舍项学生
     * @return
     */
    @DeleteMapping("/delete_check_bed_student/{batchId}/{id}")
    public Result<String> deleteCheckBedStudent(@PathVariable(required = false, name = "batchId") Integer batchId,@PathVariable(required = false, name = "id") Integer id) {
        if (batchId == null|| id == null) {
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return checkBedBatchService.deleteCheckBedStudent(batchId,id);
    }

    /**
     * 宿舍检查完成
     * @param id 宿舍检查id
     * @return
     */
    @PutMapping("/finish_check_bed/{id}")
    public Result<String> finishCheckBed(@PathVariable(required = false, name = "id") Integer id) {
        if (id == null) {
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return checkBedBatchService.finishCheckBed(id);
    }

    /**
     * 上传检查结果
     * @param id 宿舍检查id
     * @return
     */
    @PostMapping("/report_check_bed_result/{id}")
    public Result<String> reportCheckBedResult(@PathVariable(required = false, name = "id") Integer id) {
        if (id == null) {
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return checkBedBatchService.reportCheckBedResult(id);
    }
}